$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'feedback/feedbackinfos/auditlist',
        datatype: "json",
        colModel: [
            { label: '反馈ID', name: 'feedbackinfoid', index: 'FeedBackInfoId', width: 50, key: true },
            { label: '反馈者', name: 'useraccount', index: 'useraccount', width: 80 },
            { label: '项目名', name: 'projectname', index: 'projectname', width: 80 },
            { label: '创建时间', name: 'createtime', index: 'CreateTime', width: 80 },
            { label: '反馈类型', name: 'feedbacktype', index: 'feedbacktype', width: 80 ,formatter: function(value, options, row){
                    return value == 0 ? "系统反馈" : "项目反馈"}},
            { label: '审核状态', name: 'auditstatus', index: 'AuditStatus', width: 80 ,formatter: function(value, options, row){
                    switch(value){
                        case 0:
                            return '<span class="label label-warning">待审核</span>';
                        case 1:
                            return '<span class="label label-success">已解决</span>';
                        case 2:
                            return '<span class="label label-danger">未解决</span>';
                    }
                }}
        ],
        viewrecords: true,
        height: 385,
        rowNum: 10,
        rowList : [10,30,50],
        rownumbers: true,
        rownumWidth: 25,
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page",
            rows:"limit",
            order: "order"
        },
        postData:{"searchParam":vm.searchParam},
        gridComplete:function(){
            //隐藏grid底部滚动条
            $("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
        }
    });
});

//获取token
var token = localStorage.getItem("token");
//富文本框初始化
var E = window.wangEditor;
var editor = new E('#editor');

var vm = new Vue({
    el:'#rrapp',
    data:{
        //选择项目界面项目查询参数
        selectProjectSearchParam:null,
        //选择用户界面用户查询参数
        selectUserSearchParam:null,
        //主界面搜索框查询参数
        searchParam:'',
        //项目类型查询
        searchType:'',
        //保存选择界面的名称
        projectinfo:{projectname:''},
        userinfo:{useraccount:''},
        //判断当前按钮执行的什么操作的标识（新增，修改，等）
        btn:null,
        showList: true,
        title: null,
        //反馈信息
        feedbackinfos: {},
        //数据字典反馈类型数组
        feedbacktypes:[],
        //获取数据字典类型的表示
        urlProjectTypeName:'feedbacktype',

    },
    methods: {
        query: function () {
            vm.reload();
        },
        auditbtn: function (event) {
            var feedbackinfoid = getSelectedRow();
            if(feedbackinfoid == null){
                return ;
            }
            vm.showList = false;
            vm.title = "修改";

            vm.getInfo(feedbackinfoid)
        },
        audit: function (event) {
            var url = "feedback/feedbackinfos/audit";

            $.ajax({
                type: "POST",
                url: baseURL + url,
                contentType: "application/json",
                data: JSON.stringify(vm.feedbackinfos),
                success: function(r){
                    if(r.code === 0){
                        alert('操作成功', function(index){
                            vm.reload();
                            vm.feedbackinfos = {};
                            //清空选项中的数据
                            vm.feedbackinfos = {};
                            vm.projectinfo = {projectname:''};
                            vm.userinfo={useraccount:''};
                        });
                    }else{
                        alert(r.msg);
                    }
                }
            });
        },
        getInfo: function(feedbackinfoid){
            $.get(baseURL + "feedback/feedbackinfos/auditinfo/"+feedbackinfoid, function(r){
                var data = r.feedbackinfos;
                vm.feedbackinfos = data;
                //设置用户信息
                vm.userinfo.useraccount = data.useraccount;
                //设置项目信息
                vm.projectinfo.projectname = data.projectname;
                if(!vm.feedbackinfos.projectname){
                    vm.projectinfo.projectname = '无';
                }
            });
        },
        reload: function (event) {
            vm.showList = true;
            var page = $("#jqGrid").jqGrid('getGridParam','page');
            $("#jqGrid").jqGrid('setGridParam',{
                page:page,
                postData:{"searchParam":vm.searchParam,"feedbacktype":vm.searchType},
            }).trigger("reloadGrid");
            vm.userinfo = {};
        }
    }
});